package com.izhaowo.recommend.util;

import java.sql.*;

/**
 * Created by HASEE on 2019/7/18.
 */
public class MysqlUtil {
    public Connection getConn(String driver, String url, String user, String pwd)
            throws Exception {
        Class.forName(driver);
        return DriverManager.getConnection(url, user, pwd);
    }

    public ResultSet query(String driver, String url, String user,
                           String pwd, String sql) throws SQLException {
        Connection conn = null;
        try {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, user, pwd);
            Statement stmt = conn.createStatement();
            return stmt.executeQuery(sql);
        } catch (Exception e) {
            System.out.println("___ " + e.getMessage());
            return null;
        } finally {
            if (null != conn) conn.close();
        }
    }


}
